package com.ruoyi.carService.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.api.domain.OrderDetails;
import com.ruoyi.carService.service.IOrderDetailsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 洗车订单Controller
 * 
 * @author ruoyi
 * @date 2024-09-07
 */
@RestController
@RequestMapping("/orderDetails")
public class OrderDetailsController2 extends BaseController
{
    @Autowired
    private IOrderDetailsService orderDetailsService;

    /**
     * 查询洗车订单列表
     */
//    @RequiresPermissions("carService:orderDetails:list")
    @GetMapping("/list")
    public TableDataInfo list(OrderDetails orderDetails)
    {
        if(orderDetails.getStartTime() != null){
            orderDetails.setStartTime(orderDetails.getStartTime() + " 00:00:00");
        }
        if(orderDetails.getEndTime() != null){
            orderDetails.setEndTime(orderDetails.getEndTime() + " 23:59:59");
        }
        startPage();
        List<OrderDetails> list = orderDetailsService.selectOrderDetailsList(orderDetails);
        System.out.println(list);
        return getDataTable(list);
    }

    /**
     * 导出洗车订单列表
     */
    @RequiresPermissions("carService:orderDetails:export")
    @Log(title = "洗车订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderDetails orderDetails)
    {
        List<OrderDetails> list = orderDetailsService.selectOrderDetailsList(orderDetails);
        ExcelUtil<OrderDetails> util = new ExcelUtil<OrderDetails>(OrderDetails.class);
        util.exportExcel(response, list, "洗车订单数据");
    }

    /**
     * 获取洗车订单详细信息
     */
    @RequiresPermissions("carService:orderDetails:query")
    @GetMapping(value = "/{orderDetailsId}")
    public AjaxResult getInfo(@PathVariable("orderDetailsId") Long orderDetailsId)
    {
        OrderDetails orderDetails = orderDetailsService.selectOrderDetailsByOrderDetailsId(orderDetailsId);
        System.out.println(orderDetails);
        return success(orderDetails);
    }

    /**
     * 新增洗车订单
     */
//    @RequiresPermissions("carService:orderDetails:add")
    @Log(title = "洗车订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderDetails orderDetails)
    {
        return toAjax(orderDetailsService.insertOrderDetails(orderDetails));
    }

    /**
     * 修改洗车订单
     */
    @RequiresPermissions("carService:orderDetails:edit")
    @Log(title = "洗车订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderDetails orderDetails)
    {
        return toAjax(orderDetailsService.updateOrderDetails(orderDetails));
    }

    /**
     * 删除洗车订单
     */
    @RequiresPermissions("carService:orderDetails:remove")
    @Log(title = "洗车订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderDetailsIds}")
    public AjaxResult remove(@PathVariable Long[] orderDetailsIds)
    {
        return toAjax(orderDetailsService.deleteOrderDetailsByOrderDetailsIds(orderDetailsIds));
    }
}
